home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / plotting / pcgplots / gptindex.cpp < prev    next >
C/C++ Source or Header  |  1992-04-24  |  3KB  |  117 lines

  1. /*-----------------------------------------------
  2.     GPtIndex.CPP -- CGM Page Index Dialog Box
  3.     Class IndexObject
  4.   -----------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include "gpt.h"
  8. #include <stdio.h>
  9. //#include <stdarg.h>
  10. IndexObjectPt IndexObject::ThisIndexObject= NULL;
  11.  
  12.  
  13.  
  14. LPSTR lstrchr  (LPSTR str, char ch) ;
  15. LPSTR lstrrchr (LPSTR str, char ch) ;
  16.  
  17. BOOL FAR PASCAL _export IndexObject::IndexDlgProc(HWND hDlg, WORD message,
  18.                                                                 WORD wParam, LONG lParam)
  19.       {
  20.       char  cLastChar ;
  21.       short nEditLen ;
  22.       char stg[1000];
  23.       char stg2[256];
  24.       CgmObjectPt cgm;
  25.       int nIndex;
  26.       int nPage = 0;
  27.       int nItem;
  28.       HWND hList = GetDlgItem(hDlg, IDD_PLIST);
  29.       HWND hPage = GetDlgItem(hDlg, IDD_PNUM);
  30.       switch (message)  // handle WM_INITDIALOG, WMCOMMAND
  31.           {
  32.           case WM_INITDIALOG:
  33.           ThisIndexObject =  (IndexObjectPt)GetObjectPt(lParam);
  34.           cgm = ThisIndexObject->CgmObj;
  35.           cgm->GetPageText( (PSTR)stg2);
  36.           wsprintf((LPSTR)stg,"Current Page = %d",cgm->GetPicNum() );
  37.           SetDlgItemText(hDlg,IDD_MESS, stg);
  38.  
  39.           wsprintf((LPSTR)stg,"Last Page = %d", cgm->IndexCgm());
  40.           SetDlgItemText(hDlg,IDD_MESS2, stg);
  41.  
  42.           wsprintf((LPSTR)stg,"%d", cgm->GetPicNum());
  43.           SetDlgItemText(hDlg,IDD_PNUM, stg);
  44.  
  45.  
  46.           void *foo = NULL;
  47.           do
  48.              {
  49.              *stg = '\0';
  50.              cgm->GetPictureText((PSTR)stg, &foo);
  51.              wsprintf((LPSTR)stg2,"%3d : %s ",++nPage,(LPSTR)stg );
  52.              SendMessage(hList, LB_ADDSTRING, NULL, (LONG)(LPSTR)stg2);
  53.              } while (foo);
  54.           SendMessage(hList, LB_SETCURSEL, cgm->GetPicNum()-1, NULL);
  55.  
  56.           return TRUE ;
  57.  
  58.           case WM_COMMAND:
  59.           switch (wParam)   // control ID's IDD_FLIST, IDD_FNAME, IDOK, IDCANCEL
  60.               {
  61.               case IDD_PLIST:        // Something done with listbox
  62.               switch (HIWORD (lParam))   // Handles LBN_SELCHANGE, LBN_DBLCLK
  63.                   {
  64.                   case LBN_DBLCLK:
  65.                   EndDialog (hDlg,1+ SendMessage(hList,LB_GETCURSEL,NULL,NULL));
  66.                   return TRUE;
  67.  
  68.                   case LBN_SELCHANGE:   // listbox selection change
  69.                   nIndex = SendMessage(hList, LB_GETCURSEL, NULL, NULL);
  70.                   wsprintf((LPSTR)stg,"%d", nIndex +1);
  71.                   SetDlgItemText(hDlg,IDD_PNUM, stg);
  72.                   return TRUE ;
  73.                   }   // End  switch (HIWORD (lParam))
  74.               break ;     // End case IDD_FLIST
  75.  
  76.  
  77.               case IDOK:
  78.               stg[0] = 5;   // 5 bytes max
  79.               stg[1] = 0;
  80.               int num = SendMessage(hPage,EM_GETLINE,NULL,(LONG)(LPSTR)stg);
  81.               stg[num] = 0;
  82.               nItem = sscanf(stg,"%d", &num);
  83.               cgm = ThisIndexObject->CgmObj;
  84.               if (nItem !=0 && nItem !=EOF && num > 0 && num <= cgm->IndexCgm() )
  85.                   EndDialog (hDlg, num);
  86.               else
  87.                   {
  88.                   wsprintf((LPSTR)stg,"%d",
  89.                                      SendMessage(hList,LB_GETCURSEL,NULL,NULL) +1 );
  90.                   SetDlgItemText(hDlg,IDD_PNUM, stg);
  91.                   MessageBeep(0);
  92.                   }
  93.               return TRUE;
  94.  
  95.               case IDCANCEL: EndDialog (hDlg, NO_PAGE_SELECTED);  return TRUE ;
  96.               }   // End switch (wParam)
  97.           break; // End case WM_COMMAND
  98.  
  99.           }      // end switch (message)
  100.       return FALSE ;
  101.       }
  102.  
  103.  // ************* IndexObject::IndexCgm()
  104. void IndexObject::IndexCgm(HWND hWndParent)
  105.     {
  106.     DWORD lParam;
  107.     FARPROC lpfnDlgProc = MakeProcInstance(
  108.           (FARPROC)IndexObject::IndexDlgProc, Appl::hInstance) ;
  109.     // Do dialog passing pointer to  IndexObject
  110.     SetObjectPt(this, &lParam);
  111.     Page = DialogBoxParam ( Appl::hInstance, "Index",  hWndParent,
  112.                           lpfnDlgProc,lParam) ;
  113.     FreeProcInstance(lpfnDlgProc);
  114.     }
  115.  
  116.  
  117.